package com.iting.test;

import redis.clients.jedis.Jedis;

import java.util.Set;

/**
 * @author Nie ZhiPeng
 */
public class Demo01 {
    public static void main(String[] args) {

        //1.创建jedis对象。这个方法里面什么也没做，只是保存主机名和端口号
        Jedis jedis = new Jedis("localhost",6379);
        //2.调用方法
        //2.1：string类型操作
        //获取value
        String akey = jedis.get("akey");
        System.out.println("akey = " + akey);
        //判断key是否存在
        Boolean flag = jedis.exists("akey");
        System.out.println("akey是否存在："+flag);
        //jedis.del("akey");  删除key
        //存储key-value
        jedis.set("dkey","ddd");// 返回的是Ok状态

        //2.2：hash类型
        jedis.hset("user1","name","zs");
        String name = jedis.hget("user1", "name");
        System.out.println("name = " + name);

        //2.3:list类型
        jedis.rpush("list1","a","b","c");
        System.out.println(jedis.lindex("list1", 2));

        //2.4:set类型
        jedis.sadd("set1","a","b","c");
        Set<String> set1 = jedis.smembers("set1");
        for (String s : set1) {
            System.out.println(s);
        }

        //3.关闭对象
        jedis.close();
    }
}
